<?
    cria_variaveis($_POST,$_GET,$_FILES); 
?>
<p class="titulo" align="center"><?php echo $msg->get('SEQNL_MSG_02') ?></p>
<p class="subtitulo" align="center"><?php echo $msg->get('SEQNL_MSG_03') ?></p>
<p>
<div class="tabbar">
    <ul>
    <li><a href="index.php?inc=seqnl.php&modo=material"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material") echo " class=\"tabact\""; ?>><?php echo $msg->get('Material_Teorico') ?></a></li>
    <li><a href="index.php?inc=seqnl.php&modo=exemplo"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo") echo " class=\"tabact\""; ?>><?php echo $msg->get('Exemplos_Prontos') ?></a></li>
    <li><a href="index.php?inc=seqnl.php&modo=teclado"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") echo " class=\"tabact\""; ?>><?php echo $msg->get('Entrada_Teclado') ?></a></li>
    </ul>
</div>
<div id="cas">
<?php
if (!isset($Calcular)) {
    if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material")
    {
        require_once("./classes/upload.php");
        $uploads = new Upload();
        $uploads->Lista("siseqnl");
    }
    else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo") { //leitura de dados via banco de dados - modulo de exemplos e exercicios
        include "exibe_prob_seqnl_xml.php";
	}
	else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") {
	   if ((strlen($dim)==0) | ($dim<=0) | (strlen($k)==0) | ($k<=0) | (strlen($t)==0) | ($t<=0) )  {
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=seqnl.php>";
		echo $msg->get('SEQNL_MSG_04');
		echo "<input type=text size='4' maxlength='5' name=dim value=".($dim).">";
		echo "<br><br>";
		echo $msg->get('SEQNL_MSG_05');
		echo "<input type=text size='4' maxlength='5' name=k value=".($k).">";
		echo "<br><br>";
		echo $msg->get('SEQNL_MSG_06');
		echo "<input type=text size='4' maxlength='5' name=t value=".($t).">";
		echo "<br><br>";
		echo "<input type=hidden name=executar value=sim>";
		echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_02').">";
		echo "</form>"; 
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=seqnl.php>";
		echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
		echo "</form>";
	   } else {
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=seqnl.php>";
		echo $msg->get('SEQNL_MSG_04')." $dim";
        echo "<input type=hidden name=dim value=$dim>";
		//echo "<input type=text size='4' maxlength='5' name=dim value=".($dim).">";
		echo "<br><br>";
		echo $msg->get('SEQNL_MSG_05')." $k";
        echo "<input type=hidden name=k value=$k>";
		//echo "<input type=text size='4' maxlength='5' name=k value=".($k).">";
		echo "<br><br>";
		echo $msg->get('SEQNL_MSG_07')." $t";
        echo "<input type=hidden name=t value=$t>";
		//echo "<input type=text size='4' maxlength='5' name=t value=".($t).">";
		echo "<br><br>";
		echo "<p align=left><font face=Arial>".$msg->get('SEQNL_MSG_13')."</font>";
		echo "<nobr>";
		for ($i=0; $i<$dim; $i++) {
		   echo "<br><br>";
		   for ($j=0; $j<$dim; $j++) {
			$aux=$j+1;
			echo "<input type=text maxlength=10 size=5 name=matriz[".$i."][".$j."][coef] value=".$matriz[$i][$j][coef].">";
			echo "x <sub>".$aux."</sub>";
			echo "<sup><sup><sup><sup><input type=text maxlength=2 size=2 name=matriz[".$i."][".$j."][grau] value=".$matriz[$i][$j][grau]."></sup></sup></sup></sup>";
				if ($j<($dim-1)) {
				echo (" + ");
			} //end if
		   } //end for j
		   echo (" = ");
		   echo "<input type=text maxlength=10 size=5 name=matriz[".$i."][".$j."][coef] value=".$matriz[$i][$j][coef].">";
		} //end for i
		echo "</nobr>";
		echo "<br><br>";
		echo "<p align=left><b>".$msg->get('SEQNL_MSG_08')."</b>";
		echo "<br><br>";
		echo "<nobr>";
		echo "X <sub>0</sub> = (";
		for ($i=0; $i<$dim; $i++) { 
		   echo "<input type=text maxlength=10 size=5 name=vtx[".$i."] value=".$vtx[$i].">";
		   if ($i!=$dim-1) echo ", ";
		} //end for i
		echo ") <br>";
		echo "<p>";
		echo "<input class=button type=submit name=Calcular value=".$msg->get('G_MSG_04').">";
		echo "<br>";
		echo "</form>";
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=seqnl.php>";
		echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
		echo "</form>";
	   } //end if
	   echo "</body>";
	}
} else {	
    if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
        verificaBib($xml_file);
    if (!checaNumerico($matriz) || !checaNumerico($vtx))
    {
?>
        <p><font color="red"><?php echo $msg->get('Apenas_Dados_Numericos') ?></font></p>
        <p><input type="button" value="<?php echo $msg->get('Voltar') ?>" onclick="history.back()" class="button"></p>
<?php
    }
    else
    {
        echo "<br>";
        echo "".$msg->get('SEQNL_MSG_04')." ".($dim)."<br>";
        echo "".$msg->get('SEQNL_MSG_05')." ".($k)."<br>";
        echo "".$msg->get('SEQNL_MSG_07').": 10 <sup>-<font size=2> ".($t)."</sup></font><br><br>";
        echo "<p align=left><font face=Arial><b>".$msg->get('SEQNL_MSG_13')."</b></font>";
        echo "<nobr>";
        for ($i=0; $i<$dim; $i++) {                  
        echo "<br>";
        for ($j=0; $j<$dim; $j++) {
            $aux=$j+1;
                if ($j>0) {
            if ($matriz[$i][$j-1]["coef"]!=0) {
                if ($matriz[$i][$j]["coef"]>0) {
                    echo (" + ");
                } //end if
                else {
                if ($j<($dim-1)) {
                    if (($matriz[$i][$j]["coef"]==0)and($matriz[$i][$j-2]["coef"]!=0)) {
                    echo (" + ");
                    } //end if
                } //end if
                } //end else
            } //end ifcoef
            } //end ifj
            if (($matriz[$i][$j]["coef"]!=0)and($matriz[$i][$j]["coef"]!=1)) {
            echo $matriz[$i][$j]["coef"];
            } //end if
            if ($matriz[$i][$j]["coef"]!=0) {
            echo "x <sub>".$aux."</sub> <sup>".$matriz[$i][$j]["grau"]."</sup>";
            } //end if
        } //end forj
        $matriz[$i][$dim]["coef"] = - $matriz[$i][$dim]["coef"];
        if ($matriz[$i][$dim]["coef"] > 0) echo "+";
        if ($matriz[$i][$dim]["coef"] != 0) echo $matriz[$i][$dim]["coef"];
        echo " = 0"; 
        echo "<br>";    
        } //end fori
        echo "</nobr>";
        echo "<br>";
        echo "<br>";
        echo "<b>".$msg->get('SEQNL_MSG_14')."</b>";
        echo "<br>";
        echo "<br>";
        $jacob = Jacobiana($matriz,$dim);
        $parar = "nao";
        $cont = 0;
        echo "<table><tr><td>J(x)=</td><td>";
        echo "<table>";
        for ($i=0; $i<$dim; $i++) {
            //echo "("        ;
            echo "<tr>";
            for ($j=0; $j<$dim; $j++) {
            echo "<td>";
            echo $jacob[$i][$j]["coef"]."x<sub>".($j+1)."</sub><sup>".$jacob[$i][$j]["grau"]."</sup>";
            echo "</td>";
            }
            echo "</tr>";
        }
        echo "</table></td></tr></table>";
        //echo ") )";	
        echo "<br>";
        echo "<br>";
        echo "<b>".$msg->get('SEQNL_MSG_15')."</b> <br><br>";
        echo "X<sub>0</sub> = (";
        for ($i=0; $i<$dim-1; $i++) {
            echo "$vtx[$i], ";
        }
        echo $vtx[$dim-1];
        echo ")<sup>T</sup>";
        echo "<br>";
        echo "<br>";
        echo "<b>".$msg->get('SEQNL_MSG_16')."</b>";
        echo "<br>";
        require_once("classes/determinante.php");
        while (($parar == "nao") and ($cont <= $k)) {
            $f = atualiza_f($matriz,$dim,$vtx);
            $mat = atualiza_matriz_jacobiana($jacob,$dim,$vtx); 
            $continua = testa_denominadores ($mat, $dim);
            if ($continua)
            {
                $determinante = new Determinante($mat);
                $continua = !($determinante->isZero());
                if (!$continua)
                {
                    echo $msg->get('Matriz_Jacobiana_Nula');
                }
            }
            if ( $continua == true) {
                for ($i=0; $i<$dim; $i++) {
                    $mat[$i][$dim] = $f[$i];
                }	
                $vt = retrosub(tri($mat,$dim),$dim);
                for ($i=0; $i<$dim; $i++) {
                    $vt[$i] = $vt[$i] + $vtx[$i];
                }
                $parar = convergiu(atualiza_f($matriz,$dim,$vt),$dim,$t);
                $cont = $cont + 1;
                echo "<br>";
                echo "f<sub>".($cont-1)."</sub> = (";
                for ($i=0; $i<$dim-1; $i++) {
                    echo round($f[$i],$t);
                echo ", ";
                }
                echo round($f[$dim-1],$t);
                echo ")<sup>T</sup>";
                echo "<br>";      
                echo "J<sub>".($cont-1)."</sub>(X<sub>$cont</sub> - X<sub>".($cont-1)."</sub>) = -f<sub>".($cont-1)."</sub>";
                echo "   ->   X<sub>$cont</sub> = (";
                for ($i=0; $i<$dim-1; $i++) {
                    echo round($vt[$i],$t);
                echo ", ";
                }
                echo round($vt[$dim-1],$t);
                echo ")<sup>T</sup>";
                echo "<br>";
                $vtx = $vt;
            }  // end if continua
            else {
                $cont = $k+1;
            }  // end else continua
        } //end while
        echo "<br>";
        echo "<br>";
        echo "<b>".$msg->get('SEQNL_MSG_17')."</b>";
        echo "<br>";
        echo "<br>";
        if ($parar == "sim") {
            echo $msg->get('SEQNL_MSG_11')."" .($cont). "".$msg->get('SEQNL_MSG_18');
            echo "<br>";
            echo "<br>";
            echo "x = (";
            for ($i=0; $i<$dim-1; $i++) {
                echo "$vt[$i], ";
            }
            echo $vt[$dim-1];
            echo ")<sup>T</sup>";
        } //end if parar
        else if ($cont == $k+1) {
            echo $msg->get('SEQNL_MSG_10');
        } //end if cont     
        echo "<br>";
        echo "<br>";
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=seqnl.php>";
        echo "<input type=hidden name=dim value=".($dim).">";
        echo "<input type=hidden name=k value=".($k).">";
        echo "<input type=hidden name=t value=".($t).">";
        for ($i=0; $i<$dim; $i++) {
        for ($j=0; $j<$dim; $j++) {
                $aux=$j+1;
            echo "<input type=hidden name=matriz[".$i."][".$j."][coef] value=".$matriz[$i][$j]["coef"].">";
            echo "<input type=hidden name=matriz[".$i."][".$j."][grau] value=".$matriz[$i][$j]["grau"].">";
        } //end for j
        echo "<input type=hidden name=matriz[".$i."][".$j."][coef] value=".$matriz[$i][$j]["coef"].">";
        } //end for i
        echo "<input type=hidden name=executar value=sim>";
        echo "<input class=button type=submit name=Submit value=".$msg->get('SEQNL_MSG_20').">";
        echo "</form>";
        if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
        {
            echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
            echo "<script language=\"javascript\" type=\"text/javascript\">\n";
            echo "function criarLinks(value) {\n";
            echo "document.exemplos.indice.value = value;\n";
            echo "document.exemplos.action = 'index.php?inc=seqnl.php&modo=exemplo'\n";
            echo "document.exemplos.submit();\n";
            echo "}\n";
            echo "</script>";
            echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
            echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
            echo "<input type=\"hidden\" name=\"indice\">";
            echo "</form>";
            echo $msg->get('Outros_Exemplos')."<br>";
            $objeto = new DOMDocument();
            $objeto->load($xml_file);
            $filho = $objeto->getelementsbytagname("nonlin_systems");
            if ($filho->length > 0)
            {
                $temp = $filho->item(0)->getelementsbytagname("nl_system");
                for($i = 0; $i < $temp->length; $i++)
                {
                    //$sistemas[$i] = $temp[$i];
                    if ($i != 0) echo " | ";
                    if ($i == $indice) echo "<b>";
                    echo "<a href=\"javascript:criarLinks($i)\"><u>".($i+1)."</u></a>";
                    if ($i == $indice) echo "</b>";
                }
            }
            echo "<br><br>";
        }
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=seqnl.php>";
        echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
        echo "</form>";
    }
}
?>
</div>